<!doctype html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta name="viewport"
          content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Document</title>
    <style>
        body{
            display: flex;
            justify-content: center;
            align-items: center;
            height: 100vh;
        }
        nav{
            position: relative;
            display: flex;
        }
        nav a{
            text-decoration: none;
            color: black;
            font-size: 20px;
            font-weight: 900;
        }
        #maker{
            width: 0;
            height: 4px;
            background-color: black;
            transition: all 0.2s ease-in-out;
            position: absolute;
            bottom: -8px;
        }


    </style>
</head>
<body>
<nav>
    <a href="#">首页1</a>
    <a href="#">首页2</a>
    <a href="#">首页3</a>
    <a href="#">首页4</a>
    <div id="maker"></div>
</nav>
<script>
  console.log('underLineSlide.js---[加载成功]')


  const underLineSlide = document.querySelector('#maker')
  const InfoMenu = document.querySelectorAll('nav a')
  console.log(InfoMenu)
  console.log(underLineSlide)
  function indicator (e){
    underLineSlide.style.left = e.offsetLeft + 'px'
    underLineSlide.style.width = e.offsetWidth + 'px'
  }

  InfoMenu.forEach(link =>{
    link.addEventListener('click',e =>{
      indicator(e.target)
    })
  })

</script>
</body>
</html>
